package com.demo;

import java.util.List;

import model.Blog;

import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;

public class BlogController extends Controller {
	@ActionKey("/blog")
	public void index() {
		List<Blog> list = Blog.dao.find("select * from blog");
		setAttr("blogList", list);
		render("/blog.jsp");

	}

	public void update() {
		Blog blog = getModel(Blog.class);
		blog.update();

		forwardAction("/blog");

	}

	public void add() {
		Blog blog = getModel(Blog.class);
		blog.save();

		forwardAction("/blog");

	}

	public void delete() {
		// 获取表单域名为studentID的值
		// Student.dao.deleteById(getPara("studentID"));
		// 获取url请求中第一个值
		Blog.dao.deleteById(getParaToInt("id"));
		forwardAction("/blog");

	}

	public void get() {
		System.out.println("进入get");
		Blog blog = Blog.dao.findById(getParaToInt("id"));
		System.out.println(getParaToInt("id"));
		setAttr("blog", blog);
		// System.out.println(blog.toString());
		render("/blogupdate.jsp");
	}

}
